var Bus4uUtil = {
	serverUrl : 'http://localhost:8080/',//本机测试
	// serverUrl : 'http://www.chuanqi.host/',//腾讯云服务器
	setData :(k,v)=>{
		window.localStorage.setItem(k,JSON.stringify(v));
	},
	getData :(k)=>{
		return JSON.parse(window.localStorage.getItem(k));
	},
	// 设置加载层风格(页面初始化完成之前的加载风格效果,参数l为layer，load +风格类型shade为遮罩层 透明度 颜色，)
	loading:(l)=>{
			l.load(4, {
  			shade: [0.1,'#000'] 
		});
	},
	clearAllData:()=>{
		window.localStorage.clear();
		/* window.sessionStorage.clear(); */
	},
	ajax:function(url,data,callBack){
		$.ajax({
			url:url,
			type:"POST",
			contentType:"application/json;charset=utf-8",
            dataType:"JSON",
            data:JSON.stringify(data),
            beforeSend:function(){
            	layer.load(4, {shade: [0.1, '#000']});
            },
			success:function(d){
				layer.closeAll();
				if(callBack){
					callBack(d);
                }
			},
			error:function(){
				layer.closeAll();
				layer.msg("请求发送失败...", {time: 1000});
			}
		});
	},
	//生成 验证码图片 链接
	createCodeLink:function(h,e){
		$("#"+e).attr("src",h+"pc/user/getCode?"+new Date().getTime())
		$("#"+e).css({"width":"90px","height":"40px"});
	},
}

$.fn.serializeObject = function() {  
    var o = {};  
    var a = this.serializeArray();  
    $.each(a, function() {  
        if (o[this.name]) {  
            if (!o[this.name].push) {  
                o[this.name] = [ o[this.name] ];  
            }  
            o[this.name].push(this.value || '');  
        } else {  
            o[this.name] = this.value || '';  
        }  
    });  
    return o;  
}


//日期转换(将字符“Aug 5, 2009 12:51:00 PM” 转换成“2009-08-05 12:51:00” )
function formatDate(datetime){//Aug 5, 2009 12:51:00 PM
	if(datetime == "" || datetime == undefined){
		return "";
	}
	return new Date(datetime).Format("yyyy-MM-dd HH:mm:ss");
}

//时间格式化问题
Date.prototype.Format = function (fmt) {  
  var o = {  
      "M+": this.getMonth() + 1, //月份   
      "d+": this.getDate(), //日   
      "H+": this.getHours(), //小时   
      "m+": this.getMinutes(), //分   
      "s+": this.getSeconds(), //秒   
      "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
      "S": this.getMilliseconds() //毫秒   
  };  
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
  for (var k in o)  
  if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));  
  return fmt;  
}

//ajax 通用加载效果
var layindex = null
$(document).ajaxSend(function(evt, request, settings){
	layindex = layer.load(0, {shade:[0.3,"#fff"]});
});

//关闭 ajax 通用加载效果
$(document).ajaxComplete(function(evt, request, settings){
	layer.close(layindex);
});

/*
提示信息
需要在需要出发的地方添加class show_tips 以及自定义信息tipsdata="自定义提示信息"
*/
$(function(){
	$(".show_tips").click(function () {
		// let tipsStr = this.attr("tipsdata");
		let that = this;
		console.log(that)
		let tipsStr = that.getAttribute("tipsdata");
		layer.tips(tipsStr, that, {
			tips: [3, '#3595CC'],
			time: 0,
			area: 'auto',
			maxWidth:500,
			closeBtn:1
		})
	});


	/*提示信息*/
	// let tips;
	// $('.show_tips').on({
	// 	mouseenter:function(){
	// 		let that = this;
	// 		let tipsStr = that.getAttribute("tipsdata");
	// 		tips =layer.tips(tipsStr,that,{tips:[3,'#3595CC'],time:0,area: 'auto',maxWidth:500});
	// 	},
	// 	mouseleave:function(){
	// 		layer.close(tips);
	// 	}
	// });
})
function closeIframe() {
	parentData = null;
	//当你在iframe页面关闭自身时
	let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	parent.layer.close(index); //再执行关闭
}